package com.silverhaze.diamond.client.ui.report;

/**
 * This code is part of Kg.Axion project. Treat it as strictly confidential.
 * Created by Ivan Babanin.
 * Creation date: 16.09.11 2:04
 */

import com.silverhaze.diamond.client.resources.ServiceResourceContainer;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.swing.JRViewer;
import net.sf.jasperreports.swing.JRViewerController;
import net.sf.jasperreports.swing.JRViewerToolbar;

import javax.swing.*;
import java.awt.*;

/**
 * User: Babanin
 * Date: 31.08.2010
 * Time: 22:43:48
 */
public class ReportViewer extends JRViewer {
    public ReportViewer(JasperPrint jrPrint) {
        super(jrPrint);
    }

    @Override
    protected JRViewerToolbar createToolbar() {
        return new AxionJasperViewerToolbar(viewerContext);
    }

    public static void view(JasperPrint print, String title) {
        JDialog jasperViewer = new JDialog();
        jasperViewer.setLayout(new BorderLayout());

        jasperViewer.add(new ReportViewer(print), BorderLayout.CENTER);

        jasperViewer.setModal(true);
        jasperViewer.setTitle(title);
        jasperViewer.setPreferredSize(new Dimension(900, 700));
        jasperViewer.setIconImage(ServiceResourceContainer.CONTROL_PANEL.getImage());

        jasperViewer.pack();
        jasperViewer.setLocationRelativeTo(null);

        jasperViewer.setVisible(true);
    }

    class AxionJasperViewerToolbar extends JRViewerToolbar {
        public AxionJasperViewerToolbar(JRViewerController viewerContext) {
            super(viewerContext);

            remove(btnSave);
        }
    }
}

/* converted to utf8 */